import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    // 商品管理组件
    path: '/goodsManagement',
    component: Layout,
    children: [{
      path: '/goodsManagement',
      name: 'GoodsManagement',
      component: () => import('@/views/goodsManagement/index'),
      meta: { title: '商品管理', icon: 'el-icon-s-custom' }
    }]
  },
  {
    // 交易管理组件
    path: '/dealManagement',
    component: Layout,
    children: [{
      path: '/dealManagement',
      name: 'DealManagement',
      component: () => import('@/views/dealManagement/index'),
      meta: { title: '交易管理', icon: 'el-icon-s-custom' }
    }]
  }, {
    // 店铺管理组件
    path: '/storeManagement',
    component: Layout,
    children: [{
      path: '/storeManagement',
      name: 'StoreManagement',
      component: () => import('@/views/storeManagement/index'),
      meta: { title: '店铺管理', icon: 'el-icon-s-custom' }
    },
    {
      // 查看店铺详情信息
      path: '/storeManagement/detail',
      name: 'Detail',
      hidden: true,
      component: () => import('@/views/storeManagement/detail/index'),
      meta: { title: '查看店铺信息', icon: 'el-icon-user-solid' }
    }]
  },
  {
    // 管理员管理组件
    path: '/management',
    component: Layout,
    name: 'Management',
    meta: { title: '管理员管理', icon: 'el-icon-s-management' },
    children: [
      {
        // 员工管理组件
        path: 'management/staffManagement',
        name: 'Staff',
        component: () => import('@/views/management/staffManagement/index'),
        meta: { title: '员工管理', icon: 'el-icon-s-custom' }
      },
      {
        // 用户管理组件
        path: '/management/roleManagement',
        name: 'Role',
        component: () => import('@/views/management/roleManagement/index'),
        meta: { title: '角色管理', icon: 'el-icon-user-solid' }
      },
      {
        // 新增角色组件
        path: '/management/addRole',
        name: 'AddRole',
        hidden: true,
        component: () => import('@/views/management/roleManagement/addRole/index'),
        meta: { title: '编辑角色', icon: 'el-icon-user-solid' }
      },
      {
        // 商户后台账户管理组件
        path: '/management/businessAccount',
        name: 'BusinessAccount',
        component: () => import('@/views/management/businessAccount/index'),
        meta: { title: '商户后台账户管理', icon: 'el-icon-wallet' }
      }
    ]
  },
  {
    // 页面配置组件
    path: '/pageConfig',
    component: Layout,
    name: 'PageConfig',
    meta: { title: '页面配置', icon: 'el-icon-s-management' },
    children: [
      {
        // 页面轮播组件
        path: '/pageConfig/banner',
        name: 'Banner',
        component: () => import('@/views/pageConfig/banner/index'),
        meta: { title: '页面轮播', icon: 'el-icon-s-custom' }
      },
      {
        // 热搜设置组件
        path: '/pageConfig/hotSearch',
        name: 'HotSearch',
        component: () => import('@/views/pageConfig/hotSearch/index'),
        meta: { title: '热搜设置', icon: 'el-icon-user-solid' }
      },
      {
        // 帮助中心组件
        path: '/pageConfig/helpCenter',
        name: 'HelpCenter',
        component: () => import('@/views/pageConfig/helpCenter/index'),
        meta: { title: '帮助中心', icon: 'el-icon-user-solid' }
      },
      {
        // 系统协议组件
        path: '/pageConfig/systemProtocol',
        name: 'SystemProtocol',
        component: () => import('@/views/pageConfig/systemProtocol/index'),
        meta: { title: '系统协议', icon: 'el-icon-user-solid' }
      }
    ]
  },
  {
    // 财务对账组件
    path: '/financeCheck',
    component: Layout,
    name: 'FinanceCheck',
    meta: { title: '财务对账', icon: 'el-icon-s-management' },
    children: [
      {
        // 页面轮播组件
        path: '/financeCheck/financeCheckList',
        name: 'FinanceCheckList',
        component: () => import('@/views/financeCheck/financeCheckList/index'),
        meta: { title: '商务对账单', icon: 'el-icon-s-custom' }
      },
      {
        // 打款凭证组件
        path: '/financeCheck/proof',
        name: 'Proof',
        component: () => import('@/views/financeCheck/proof/index'),
        meta: { title: '打款凭证', icon: 'el-icon-user-solid' }
      }
    ]
  },
  {
    // 待处理组件
    path: '/pending',
    component: Layout,
    name: 'Pending',
    meta: { title: '待处理', icon: 'el-icon-s-management' },
    children: [
      {
        // 店铺审核组件
        path: '/pending/storeAudit',
        name: 'StoreAudit',
        component: () => import('@/views/pending/storeAudit/index'),
        meta: { title: '店铺审核', icon: 'el-icon-s-custom' }
      },
      {
        // 商品审核组件
        path: '/pending/goodsAudit',
        name: 'GoodsAudit',
        component: () => import('@/views/pending/goodsAudit/index'),
        meta: { title: '商品审核', icon: 'el-icon-s-custom' }
      },
      {
        // 提现管理组件
        path: '/pending/cashManagement',
        name: 'CashManagement',
        component: () => import('@/views/pending/cashManagement/index'),
        meta: { title: '提现管理', icon: 'el-icon-s-custom' },
        children: [
          {
            // 提现审核
            path: '/pending/cashManagement/cashAudit',
            name: 'CashAudit',
            component: () => import('@/views/pending/cashManagement/cashAudit/index'),
            meta: { title: '提现审核', icon: 'el-icon-s-custom' }
          },
          {
            // 财务打款
            path: '/pending/cashManagement/financialPayment',
            name: 'financialPayment',
            component: () => import('@/views/pending/cashManagement/financialPayment/index'),
            meta: { title: '财务打款', icon: 'el-icon-s-custom' }
          }
        ]
      },
      {
        // 问题反馈组件
        path: '/pending/feedBack',
        name: 'FeedBack',
        component: () => import('@/views/pending/feedBack/index'),
        meta: { title: '问题反馈', icon: 'el-icon-s-custom' }
      },
      {
        // 合作信息组件
        path: '/pending/cooperationInfomation',
        name: 'CooperationInfomation',
        component: () => import('@/views/pending/cooperationInfomation/index'),
        meta: { title: '合作信息', icon: 'el-icon-s-custom' }
      }
    ]
  },
  {
    // 支付管理组件
    path: '/payManagement',
    component: Layout,
    name: 'PayManagement',
    meta: { title: '支付管理', icon: 'el-icon-s-management' },
    children: [
      {
        // 支付流水组件
        path: '/payManagement/paymentFlowWater',
        name: 'PaymentFlowWater',
        component: () => import('@/views/payManagement/paymentFlowWater/index'),
        meta: { title: '支付流水', icon: 'el-icon-s-custom' }
      },
      {
        // 推广明细组件
        path: '/payManagement/popularizeDetail',
        name: 'PopularizeDetail',
        component: () => import('@/views/payManagement/popularizeDetail/index'),
        meta: { title: '推广明细', icon: 'el-icon-s-custom' }
      },
      {
        // 团队奖励组件
        path: '/payManagement/teamAward',
        name: 'teamAward',
        component: () => import('@/views/payManagement/teamAward/index'),
        meta: { title: '团队奖励', icon: 'el-icon-s-custom' }
      }

    ]
  },
  {
    // 代理商组件
    path: '/agent',
    component: Layout,
    children: [{
      path: '/agent',
      name: 'Agent',
      component: () => import('@/views/agent/index'),
      meta: { title: '代理商', icon: 'el-icon-s-custom' }
    }]
  },
  {
    // 会员管理组件
    path: '/memberManagement',
    component: Layout,
    children: [{
      path: '/memberManagement',
      name: 'MemberManagement',
      component: () => import('@/views/memberManagement/index'),
      meta: { title: '会员管理', icon: 'el-icon-s-custom' }
    }]
  },
  {
    // 代理分成配置组件
    path: '/agentShare',
    component: Layout,
    name: 'AgentShare',
    meta: { title: '代理分成配置', icon: 'el-icon-s-management' },
    children: [
      {
        // 个人推广金币组件
        path: '/agentShare/personalPopularize',
        name: 'PersonalPopularize',
        component: () => import('@/views/agentShare/personalPopularize/index'),
        meta: { title: '个人推广金币', icon: 'el-icon-s-custom' }
      },
      {
        // 团队奖励组件
        path: '/agentShare/teamAward',
        name: 'TeamAward',
        component: () => import('@/views/agentShare/teamAward/index'),
        meta: { title: '团队奖励', icon: 'el-icon-s-custom' },
        children: [
          {
            // 本月参数
            path: '/agentShare/teamAward/currentMonthParam',
            name: 'CurrentMonthParam',
            component: () => import('@/views/agentShare/teamAward/currentMonthParam/index'),
            meta: { title: '本月参数', icon: 'el-icon-s-custom' }
          },
          {
            // 下月预设
            path: '/agentShare/teamAward/nextMonthSet',
            name: 'NextMonthSet',
            component: () => import('@/views/agentShare/teamAward/nextMonthSet/index'),
            meta: { title: '下月预设', icon: 'el-icon-s-custom' }
          }
        ]
      }
    ]
  },
  {
    // 资讯管理组件
    path: '/messages',
    component: Layout,
    name: 'Messages',
    meta: { title: '资讯管理', icon: 'el-icon-s-management' },
    children: [
      {
        // 分类配置组件
        path: '/messages/classifyConfig',
        name: 'ClassifyConfig',
        component: () => import('@/views/messages/classifyConfig/index'),
        meta: { title: '分类配置', icon: 'el-icon-s-custom' }
      },
      {
        // 文章管理组件
        path: '/messages/articleManagement',
        name: 'ArticleManagement',
        component: () => import('@/views/messages/articleManagement/index'),
        meta: { title: '文章管理', icon: 'el-icon-s-custom' }
      },
      {
        // 视频管理组件
        path: '/messages/videoManagement',
        name: 'VideoManagement',
        component: () => import('@/views/messages/videoManagement/index'),
        meta: { title: '视频管理', icon: 'el-icon-s-custom' }
      },
      {
        // 靶向药专题组件
        path: '/messages/targetedDrugTopic',
        name: 'TargetedDrugTopic',
        component: () => import('@/views/messages/targetedDrugTopic/index'),
        meta: { title: '靶向药专题', icon: 'el-icon-s-custom' },
        children: [
          {
            // 专题列表
            path: '/messages/targetedDrugTopic/topicList',
            name: 'TopicList',
            component: () => import('@/views/messages/targetedDrugTopic/topicList/index'),
            meta: { title: '专题列表', icon: 'el-icon-s-custom' }
          },
          {
            // 基因种类
            path: '/messages/targetedDrugTopic/geneTypes',
            name: 'GeneTypes',
            component: () => import('@/views/messages/targetedDrugTopic/geneTypes/index'),
            meta: { title: '基因种类', icon: 'el-icon-s-custom' }
          }
        ]
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
